keep working.
code: hw1_siwon.pro

Variables' information of 'COARE_soundings_goodset.nc' file:

IRTEMP FLOAT = Array[1726]
NCID LONG = 8
NFDOEJROE STRING = Array[1]
P FLOAT = Array[1726, 181]
RH FLOAT = Array[1726, 181]
T FLOAT = Array[1726, 181]

#4. mixing ratio (qv) profiles of each 1726 soundings

qv = RH/100.*mixrat(T,p)
num4.png

#5. mean mixing ratio (qe) and mean temperature (Te) profile

qe = total(qv,1) / n_elements(qv(*,0))
Te = total( T,1) / n_elements( T(*,0))
Picture_4.png

#6. entropy (s0), total water (qt0), pressure (p0) of a near-surface parcel

s0 = se(0) & p0 = pe(0) & qt0 = qe(0)

Answer:
qt0 = 0.0179396 [kg/kg]
p0 = 1000.00 [mb]
s0 = 260.442

< supporting figures: entropy profiles >
1. 1726 entropy profiles are calculated first, but can't be averaged because of some "missing values" of entropy profiles produced during entropy calculation in IDL.
2. Mean entropy profile is calculated by Te, pe (mean pressure profile), and qe directly.
Picture_3.png
Picture_5.png

#7. Vertically inverted parcel temperature (Tp) and mixing ratio (qvp) from the bottom level

invert_s, se(0),pe,qe(0), Tp,qvp
num7.png

#8. Condensed water profile (qc)

qc = qt0 - qvp
Picture_7.png

#9. density temperature of environment (Trhoe) and a parcel (Trhop)

Trhoe = (Te+273.2) *(1+qe /0.622) / (1+ qe ) - 273.2
Trhop = (Tp+273.2) *(1+qvp/0.622) / (1+qvp(0)) - 273.2

< extra: virtual temperature of environment (Tve) and a parcel (Tvp) >
Tve = (Te+273.2)*(1+0.61*qe ) - 273.2 ;;; it should be same as Trhoe for unsaturated env.
Tvp = (Tp+273.2)*(1+0.61*qvp) - 273.2
num9.png

#10. thermal buoyancy force (B)

B = 9.8*((Trhop+273.2)-(Tve+273.2)) / (Tve+273.2)
Picture_9.png

#11. CAPE like energy by cumulative sum

Tvabs = (T+273.2)*(1+0.61*qv)
Tv = Tvabs - 273.2
dz = (287.*Tvabs/9.8/p)*5 ;;; dp = 5mb
z = total(dz, 2, /cum)

CAPE = total( B*dz(0,*), /cum) ;;; might see kind of both CIN and CAPE...
CAPE2 = total((B>0)*dz(0,*), /cum) ;;; only the case if B>0
num11.png

Until now, it's "reversible process".


From now, it's "irreversible process (=pseudoadiabat)".

This is based on Brian's "Raymond-Blyth type buoyancy sorting model", b_profile_ice_entrain.pro

It includes precipitation & freezing processes.



- Re-definition of variables in reversible process w/o freezing process
Tp_rev = Tp & qvp_rev = qvp & Trhop_rev = Trhop & B_rev = B & CAPE_rev = CAPE
- Calculate Latent Heat of Freezing
;;;; LWMAX = 0 for pseudoadiabatic / = large for reversible
Cl = 4218. ; liquid water heat capacity
; Latent heat of freezing, from Iribarne & Godson
Lfdata = [333,312,289,264,236,204]*1.0e3 & Tlf = [0,-10,-20,-30,-40,-50]
Lf = interpx(-Tlf, LFdata, -Tp)

- Calculate reversible qvp_rev_ice and Tp_rev_ice again w/ freezing process

LWMAX = 999.
for i=0,1 do begin
xsH2O = (qt0 - qvp - LWMAX) > 0 ; total condensed water mixing ratio --> zero for reversible process
ds_precip = Cl* alog( (Tp+273.2)/273.2 )* deriv(xsH2O) ; entropy loss due to the loss of liquid cloud drops to precip. or ice --> also zero for reversible process
ds_freezing = -Lf* deriv( qvp/(273.2+Tp) )* (Tp lt 0) ; entropy gain due to the presence of ice & the freezing of cloud drops
freezelevel = min( where(Tp le 0) )
freeze_s = Lf *( (qt0-qvp(freezelevel)) <LWMAX) /$
(273.2+Tp(freezelevel))
newsp = s0 - cumulate(ds_precip) +freeze_s*(Tp lt 0)
invert_s, newsp, pe, qt0-xsH2O, Tp, qvp
endfor
Tp_rev_ice = Tp & qvp_rev_ice = qvp

- Calculate irreversible qvp_irr_precip and Tp_irr_precip w/ only precipitation process

Tp = Tp_rev & qvp = qvp_rev
LWMAX = 0.
for i=0,1 do begin
xsH2O = (qt0 - qvp - LWMAX) > 0 ; total condensed water mixing ratio
ds_precip = Cl* alog( (Tp+273.2)/273.2 )* deriv(xsH2O) ; entropy loss due to the loss of liquid cloud drops to precip. or ice
newsp = s0 - cumulate(ds_precip)
invert_s, newsp, pe, qt0-xsH2O, Tp, qvp
endfor
Tp_irr_precip = Tp & qvp_irr_precip = qvp
- Calculate irreversible qvp_irr_precip_ice and Tp_irr_precip_ice w/ both precipitation & freezing process
Tp = Tp_rev & qvp = qvp_rev
LWMAX = 0.
for i=0,1 do begin
xsH2O = (qt0 - qvp - LWMAX) > 0 ; total condensed water mixing ratio
ds_precip = Cl* alog( (Tp+273.2)/273.2 )* deriv(xsH2O) ; entropy loss due to the loss of liquid cloud drops to precip. or ice
ds_freezing = -Lf* deriv( qvp/(273.2+Tp) )* (Tp lt 0) ; entropy gain due to the presence of ice & the freezing of cloud drops
freezelevel = min( where(Tp le 0) )
freeze_s = Lf *( (qt0-qvp(freezelevel)) <LWMAX) /$
(273.2+Tp(freezelevel))
newsp_precip = s0 - cumulate(ds_precip)
newsp_all = s0 - cumulate(ds_precip) + cumulate(ds_freezing) + freeze_s*(Tp lt 0)
invert_s, newsp, pe, qt0-xsH2O, Tp, qvp
endfor
Tp_irr_precip_ice = Tp & qvp_irr_precip_ice = qvp
num12-7.png
- Calculate density temperature, Trhop_pseudo
Trhop_rev_ice = (Tp_rev_ice+273.2) *(1+qvp_rev_ice/0.622)/(1+qt0) - 273.2
Trhop_irr_precip = (Tp_irr_precip+273.2) *(1+qvp_irr_precip/0.622)/(1+qvp_irr_precip) - 273.2
Trhop_irr_precip_ice = (Tp_irr_precip_ice+273.2) *(1+qvp_irr_precip_ice/0.622)/(1+qvp_irr_precip_ice) - 273.2
num12-9.png
- Calculate Buoyancy, B_pseudo
B_rev_ice = 9.8*((Trhop_rev_ice+273.2)-(Tve+273.2))/(Tve+273.2)
B_irr_precip = 9.8*((Trhop_irr_precip+273.2)-(Tve+273.2))/(Tve+273.2)
B_irr_precip_ice = 9.8*((Trhop_irr_precip_ice+273.2)-(Tve+273.2))/(Tve+273.2)
num12-10.png
- Calculate CAPE, CAPE_pseudo
CAPE_rev_ice = total(B_rev_ice*dz(0,*), /cum)
CAPE_irr_precip = total(B_irr_precip*dz(0,*), /cum)
CAPE_irr_precip_ice = total(B_irr_precip_ice*dz(0,*), /cum)
num12-11.png